import 'package:flutter/foundation.dart';
import 'package:hc_voice_plugin/hc_voice_plugin.dart';

class HCBotASR {
  Function? onSleep;
  Function? onAwake;

  Function(String)? onASRCompleted;

  bool _isSleep = false;

  bool get isSleep => _isSleep;

  Future sleep() async {
    debugPrint("HCAIBot sleep");
    await HcVoicePlugin().sleep(isTtsStop: false);
    _isSleep = true;

    if (onSleep != null) {
      onSleep!();
    }
  }

  HCBotASR() {
    HcVoicePlugin().awake.listen((event) {
      _isSleep = false;
    });
  }

  Future pause() async {
    await HcVoicePlugin().stop(isTtsStop: false);
  }

  Future resume() async {
    if (_isSleep) {
      return;
    }
    await HcVoicePlugin().start();
  }
}
